package com.ruoyi.web.controller.news.api;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.domain.news.NewsStudyTrain;
import com.ruoyi.system.domain.news.query.NewsStudyTrainQuery;
import com.ruoyi.system.domain.news.vo.NewsStudyTrainVo;
import com.ruoyi.system.service.news.NewsStudyTrainService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/news/newsStudyTrain")
@Api(value = "newsStudyTrainApiController", tags  = "学习培训Api")
public class NewsStudyTrainApiController extends BaseController {

	@Resource
	private NewsStudyTrainService newsStudyTrainService;

	@ApiOperation(value = "获取单个学习培训信息", notes = "获取单个学习培训信息")
	@GetMapping("/getById")
	public R<NewsStudyTrain> getById(@RequestParam(value = "id") Long id) {
		NewsStudyTrainQuery newsStudyTrainQuery = new NewsStudyTrainQuery();
		newsStudyTrainQuery.setId(id);
		List<NewsStudyTrainVo> newsStudyTrainList = newsStudyTrainService.getNewsStudyTrainList(newsStudyTrainQuery);
		if (newsStudyTrainList!=null&&newsStudyTrainList.size()>0) {
			return R.ok(newsStudyTrainList.get(0));
		} else {
			return R.fail("数据不存在");
		}
	}

	@ApiOperation(value = "获取学习培训信息列表")
	@PostMapping(value = "/list")
	public R<PageInfo<NewsStudyTrainVo>> list(@RequestBody NewsStudyTrainQuery newsStudyTrainQuery) {
        newsStudyTrainQuery.setIsEnable("1");
		List<NewsStudyTrainVo> newsStudyTrainList = newsStudyTrainService.getNewsStudyTrainList(newsStudyTrainQuery);
		return R.ok(new PageInfo<>(newsStudyTrainList));
	}
}
